﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace project.B12.application.Extensions
{
    public class ResultToColorConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value!=null)
            {
                var result = value.ToString();
                string parameterValue = parameter as string; 
                switch (parameterValue)
                {
                    case "Border":
                        {
                            return "#e0e0e0";
                        }
                    case "Image":
                        {
                            if (result == "S")
                            {
                                return "#6CD67E";//绿色
                            }
                            if (result == "I")
                            {
                                return "#EEEC86";//黄色
                            }
                            if (result == "R")
                            {
                                return "#EEA4A4";//红色
                            }
                            return "#e0e0e0";
                        }
                    case "Ring":
                        {
                            try
                            {
                                string[] rets = result.Split('/');
                                if (Math.Max(sbyte.Parse(rets[0]), sbyte.Parse(rets[1])) < 4)
                                {
                                    return "#ffffff";//阴性
                                }
                                else
                                {
                                    return "#616161";//阳性
                                }
                            }
                            catch
                            {
                                return "Transparent";
                            }
                        }
                    case "Text":
                        {
                            try
                            {
                                string[] rets = result.Split('/');
                                if (Math.Max(sbyte.Parse(rets[0]), sbyte.Parse(rets[1])) < 4)
                                {
                                    return "#212121";//阴性,灰色
                                }
                                else
                                {
                                    return "#ffffff";//阳性,白色
                                }
                            }
                            catch
                            {
                                return "Transparent";
                            }
                        }
                    default:
                        return "Transparent";
                }
            }
            else
                return "Transparent";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
